package com.ztjava.score.controller;

import com.jfinal.aop.Duang;
import com.ztjava.core.Constant;
import com.ztjava.core.annotation.ControllerClass;
import com.ztjava.core.base.BaseController;
import com.ztjava.core.client.PortalClient;
import com.ztjava.core.tool.ConfigTool;
import com.ztjava.ext.auth.annotation.UserController;
import com.ztjava.ext.auth.annotation.UserMethod;
import com.ztjava.ext.auth.bean.AuthSession;
import com.ztjava.score.model.ScoreType;
import com.ztjava.score.service.ScoreService;

@ControllerClass(client=PortalClient.class,path="/score")
@UserController(portal=Constant.P_PORTAL)
public class ScorePortalController extends BaseController{
	/*************
	 *ScorePortalController.java
	 *@AutoJavaCode
	 *2017-10-29 16:27:02
	**************/
	private static ScoreService scoreService = Duang.duang(ScoreService.class);
	/*************
	 *修改Type
	**************/
	@UserMethod("ScoreType")
	public void addEditType(){
		Integer id = getParaToInt("id",0);
		ScoreType scoreType = new ScoreType();
		if(id>0){
			scoreType = ScoreType.dao.findById(id);
		}
		setAttr("scoreType",scoreType);
		render("addEditType.html");
	}

	/*************
	 *保存Type
	**************/
	@UserMethod("ScoreType")
	public void saveType(){
		AuthSession authSession = getAttr(Constant.AUTHSESSION);
		ScoreType scoreType = getModel(ScoreType.class);
		saveModel(scoreType,authSession.getId());
		ConfigTool.dbToBaseData("SCORE_TYPE", ScoreType.tablename, "id asc");
		renderSuccess();
	}

	/*************
	 *Type列表
	**************/
	@UserMethod("ScoreType")
	public void typeList(){
		
		if(!getPara("is_ajax","F").equals("T")){
			render("typeList.html");
			return;
		}
		renderPageJson(scoreService.getTypePage(client, getParaMap()));
	}

	/*************
	 *批量删除Type
	**************/
	@UserMethod("ScoreType")
	public void batchDeleteType(){
		String[] btSelectItem = getParaValues("btSelectItem");
		scoreService.batchDelete(ScoreType.tablename, btSelectItem);
		ConfigTool.dbToBaseData("SCORE_TYPE", ScoreType.tablename, "id asc");
		renderSuccess();
	}
	/*************
	 *Sign列表
	**************/
	@UserMethod("ScoreSign")
	public void signList(){
		
		if(!getPara("is_ajax","F").equals("T")){
			keepPara();
			render("signList.html");
			return;
		}

		
		renderPageJson(scoreService.getSignPage(client, getParaMap()));
	}


/*************
 *Record列表
**************/
@UserMethod("ScoreRecord")
public void recordList(){
	
	if(!getPara("is_ajax","F").equals("T")){
		keepPara();
		render("recordList.html");
		return;
	}

	
	renderPageJson(scoreService.getRecordPage(client, getParaMap()));
}

}
